Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: bank precompile #2860

Merged
merged 43 commits into from
Sep 27, 2024
Merged

feat!: bank precompile #2860

merged 43 commits into from
Sep 27, 2024

Conversation

fbac
Copy link
Contributor

@fbac fbac commented Sep 10, 2024

Description

Closes #2791.

Implements a bank precompile, with the following functions:

  • deposit: deposits ZRC20 as a cosmos token.
  • withdraw: withdraw ZRC20 from a cosmos token.
  • balance: reports the EOA balance for a given ZRC20 cosmos token.

WIP

  • Deposit function
  • Deposit event
  • Withdraw function
  • Withdraw event
  • BalanceOf function
  • Remove DEBUG lines
  • Full e2e coverage direct call
  • Full e2e coverage through contract
  • Unit testing
  • Deposit and Withdraw to check tokens are ZRC20

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Integrated a bank precompiled contract for managing ZRC20 token deposits and withdrawals.
    • Added support for a new account configuration for user banking operations in local network setups.
    • Introduced end-to-end tests for bank precompile functionality, enhancing testing coverage.
  • Bug Fixes

    • Improved logic for managing blocked addresses to allow bank precompile interactions.
  • Documentation

    • Updated changelog to reflect the addition of the bank precompiled contract.
  • Tests

    • Expanded end-to-end testing suite to include tests for bank-related functionalities.
  • Chores

    • Minor adjustments to scripts and configurations for better clarity and functionality.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces a precompiled contract for managing banking operations within a blockchain environment, allowing for the deposit and withdrawal of ZRC20 tokens as Cosmos bank tokens. It includes updates to various files, implementing functions for balance inquiries, deposits, and withdrawals. Additionally, the changes enhance error handling and logging capabilities, ensuring robust interactions with the banking contract.

Changes

Files Change Summary
Dockerfile-localnet Modified COPY commands to include trailing slashes for clarity in binary placement.
app/app.go Integrated bankprecompile package; updated stateful contract handling and blocked addresses logic.
changelog.md Added entry for the bank precompiled contract.
cmd/zetae2e/config/localnet.yml Introduced new account configuration for user_bank_precompile.
cmd/zetae2e/local/local.go Added end-to-end test case for bank precompiles.
codecov.yml Updated ignore list to exclude precompiles/bank/IBank.go from coverage reports.
contrib/localnet/orchestrator/start-zetae2e.sh Renamed user account for precompile tests and removed redundant funding lines.
contrib/localnet/scripts/start-zetacored.sh Added new account for bank precompile in genesis block configuration.
e2e/e2etests/e2etests.go Introduced new constants and E2E test for bank precompiles.
e2e/e2etests/test_precompiles_bank.go Implemented E2E test for deposit and withdrawal operations of bank precompile.
precompiles/bank/*.go Introduced various functionalities for the banking contract, including deposit, withdraw, and balance inquiry methods.
precompiles/types/errors.go Enhanced error handling with new error types and detailed messages.
precompiles/types/types.go Added ContractCaller interface for invoking contract methods.

Assessment against linked issues

Objective Addressed Explanation
Develop a precompile allowing to convert ERC20 into Cosmos bank tokens ( #2791 )

Possibly related PRs

Suggested labels

no-changelog


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fbac fbac force-pushed the feat/bank-precompile branch 3 times, most recently from 004c3af to 3eecbbf Compare September 11, 2024 11:02
@fbac fbac force-pushed the feat/bank-precompile branch 3 times, most recently from 977f122 to 55aaf96 Compare September 11, 2024 17:41
precompiles/bank/method_balanceof.go Outdated Show resolved Hide resolved
precompiles/bank/method_deposit.go Outdated Show resolved Hide resolved
precompiles/bank/method_deposit.go Outdated Show resolved Hide resolved
precompiles/bank/method_deposit.go Outdated Show resolved Hide resolved
precompiles/bank/method_deposit.go Outdated Show resolved Hide resolved
@fbac fbac force-pushed the feat/bank-precompile branch 3 times, most recently from 4099e86 to ab771a8 Compare September 16, 2024 10:11
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main request for change: change the order of instruction in the withdraw operation
Otherwise mainly suggestions for error handling

cmd/zetae2e/local/local.go Show resolved Hide resolved
precompiles/bank/method_balance_of.go Show resolved Hide resolved
precompiles/bank/method_deposit.go Show resolved Hide resolved
precompiles/bank/method_deposit.go Outdated Show resolved Hide resolved
precompiles/bank/method_deposit.go Show resolved Hide resolved
precompiles/bank/method_deposit.go Outdated Show resolved Hide resolved
precompiles/bank/method_withdraw.go Outdated Show resolved Hide resolved
precompiles/bank/method_withdraw.go Outdated Show resolved Hide resolved
precompiles/bank/method_withdraw.go Outdated Show resolved Hide resolved
precompiles/bank/method_withdraw.go Outdated Show resolved Hide resolved
precompiles/bank/const.go Outdated Show resolved Hide resolved
precompiles/bank/const.go Show resolved Hide resolved
@fbac fbac enabled auto-merge September 27, 2024 10:55
@lumtis lumtis removed the TSS_MIGRATION_TESTS Run TSS migration tests label Sep 27, 2024
@fbac fbac disabled auto-merge September 27, 2024 11:36
@fbac fbac enabled auto-merge September 27, 2024 11:36
@fbac fbac added this pull request to the merge queue Sep 27, 2024
Merged via the queue into develop with commit 3568cd4 Sep 27, 2024
32 of 33 checks passed
@fbac fbac deleted the feat/bank-precompile branch September 27, 2024 12:12
morde08 pushed a commit that referenced this pull request Oct 2, 2024
* feat: bank precompile

* feat: add deposit

* feat: extend deposit

* PoC: spend amount on behalf of EOA

* feat: expand deposit with transferFrom

* use CallEVM instead on ZRC20 bindings

* divide the contract into different files

* initialize e2e testing

* remove duplicated funding

* add codecov

* expand e2e

* fix: wait for deposit tx to be mined

* apply first round of reviews

* cover al error types test

* fixes using time.Since

* Include CallContract interface

* fix eth events in deposit precompile method

* emit Deposit event

* add withdraw function

* finalize withdraw

* pack event arguments generically

* add high level event function

* first round of review fixes

* second round of reviews

* create bank account when instantiating bank

* e2e: add good and bad scenarios

* modify fmt

* chore: group input into eventData struct

* docs: document bank's methods

* chore: generate files with suffix .gen.go

* chore: assert errors with errorIs

* chore: reset e2e test by resetting allowance

* test: add first batch of unit test

* test: cover all cases

* test: complete unit test cases

* include review suggestions

* include e2e through contract

* test: add e2e through contract complete

* test: revert balance between tests

* Update precompiles/bank/const.go

Co-authored-by: Lucas Bertrand <[email protected]>

* fix: changed coin denom

---------

Co-authored-by: skosito <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Oct 3, 2024
…guration (#2953)

* update artillery config

* more fixes

* feat: integrate authenticated calls smart contract functionality into protocol (#2904)

* e2e tests and modifications for authenticated call

* extend test with sender check and revert case

* separate tests into separate files

* cleanup

* withdraw and call support and tests

* bump protocol contracts

* split tests into separate files

* small cleanup

* fmt

* generate

* lint

* changelog

* PR  comments

* fix case in proto

* bump vote inbound gas limit in zetaclient

* fix test

* generate

* fixing tests

* call options non empty

* generate

* test fix

* rename gateway caller

* pr comments rename tests

* PR comment

* generate

* tests

* update tests fixes

* tests fixes

* fix

* test fix

* feat!: bank precompile (#2860)

* feat: bank precompile

* feat: add deposit

* feat: extend deposit

* PoC: spend amount on behalf of EOA

* feat: expand deposit with transferFrom

* use CallEVM instead on ZRC20 bindings

* divide the contract into different files

* initialize e2e testing

* remove duplicated funding

* add codecov

* expand e2e

* fix: wait for deposit tx to be mined

* apply first round of reviews

* cover al error types test

* fixes using time.Since

* Include CallContract interface

* fix eth events in deposit precompile method

* emit Deposit event

* add withdraw function

* finalize withdraw

* pack event arguments generically

* add high level event function

* first round of review fixes

* second round of reviews

* create bank account when instantiating bank

* e2e: add good and bad scenarios

* modify fmt

* chore: group input into eventData struct

* docs: document bank's methods

* chore: generate files with suffix .gen.go

* chore: assert errors with errorIs

* chore: reset e2e test by resetting allowance

* test: add first batch of unit test

* test: cover all cases

* test: complete unit test cases

* include review suggestions

* include e2e through contract

* test: add e2e through contract complete

* test: revert balance between tests

* Update precompiles/bank/const.go

Co-authored-by: Lucas Bertrand <[email protected]>

* fix: changed coin denom

---------

Co-authored-by: skosito <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>

* feat: add sender to revert context (#2919)

* e2e tests and modifications for authenticated call

* extend test with sender check and revert case

* separate tests into separate files

* cleanup

* withdraw and call support and tests

* bump protocol contracts

* split tests into separate files

* small cleanup

* fmt

* generate

* lint

* changelog

* PR  comments

* fix case in proto

* bump vote inbound gas limit in zetaclient

* fix test

* generate

* fixing tests

* call options non empty

* generate

* test fix

* rename gateway caller

* pr comments rename tests

* PR comment

* generate

* tests

* add sender in test contract

* extend e2e tests

* generate

* changelog

* PR comment

* generate

* update tests fixes

* tests fixes

* fix

* test fix

* gas limit fixes

* PR comment fix

* fix bad merge

* ci: add option to enable monitoring stack (#2927)

* ci: add option to enable monitoring stack

* start prometheus faster

* update

* ci: add rpcimportable test (#2817)

* ci: add rpcimportable test

* add ci

* fmt

* use github.com/btcsuite/btcd/btcutil in pkg/chains

* remove app imports types tests

* use standalone sdkconfig package

* fix policies test

* move crosschain keeper tests from types to keeper

* never seal config in tests

* use zeta-chain/ethermint#126

* add some comments

* use merged ethermint hash

* show resulting go.mod

* ci: Add SARIF upload to GitHub Security Dashboard (#2929)

* add semgrep sarif upload to GHAS

* added comment to clairfy the usage of the utility script

* use ghcr.io instead

* add tag to image

* bad org name

---------

Co-authored-by: jkan2 <[email protected]>

* fix: add recover to InitChainer to diplay informative message when starting a node from block 1 (#2925)

* add recover to InitChainer

* generate files

* add docs link to error message

* move InitChainErrorMessage to app.go

* Update app/app.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* use const for message

---------

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* test: add wait for block to tss migration test (#2931)

* add wait for block to tss migration test

* add comments

* refactor identifiers

* rename checkNumberOfTssGenerated to checkNumberOfTSSGenerated

* chore: allow full zetaclient config overlay (#2945)

* test(e2e): add gateway upgrade in upgrade test (#2932)

* add gateway upgrade

* change reference

* add v2 setup for all tests

* test v2 in light upgrade

* refactor setup to use custody v2 directly

* chore: improve localnet build performance (#2928)

* chore: improve localnet build performance

* propagate NODE_VERSION and NODE_COMMIT

* update hashes

---------

Co-authored-by: skosito <[email protected]>
Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>
Co-authored-by: Alex Gartner <[email protected]>
Co-authored-by: jkan2 <[email protected]>
Co-authored-by: jkan2 <[email protected]>
Co-authored-by: Tanmay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a precompile allowing to map ERC20s into bank tokens
7 participants